package com.cropdoctor;


import com.aliyun.oss.OSSClient;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.cropdoctor.model.constants.SearchConstants;
import io.redisearch.client.Client;
import org.apache.http.HttpHost;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.web.filter.FormContentFilter;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@MapperScan("com.cropdoctor.mapper")
@EnableOpenApi
public class CropDoctorApplication {
    public static void main(String[] args) {
        SpringApplication.run(CropDoctorApplication.class, args);
    }

    /*es客户端*/
//    @Value("${elasticsearch.host}")
//    private String elasticsearchHost;
//
//    @Value("${elasticsearch.port}")
//    private int elasticsearchPort;
//    @Bean
//    public RestHighLevelClient restHighLevelClient(){
//        return new RestHighLevelClient(RestClient.builder(
//                HttpHost.create("http://" + elasticsearchHost + ":" + elasticsearchPort)
//        ));
//    }

    /*mq消息转换器*/
    @Bean
    public MessageConverter messageConverter(){
        // 1.定义消息转换器
        Jackson2JsonMessageConverter jackson2JsonMessageConverter = new Jackson2JsonMessageConverter();
        // 2.配置自动创建消息id，用于识别不同消息，也可以在业务中基于ID判断是否是重复消息
        jackson2JsonMessageConverter.setCreateMessageIds(true);
        return jackson2JsonMessageConverter;
    }

    /**
     * mybatis-plus
     * 添加分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));//如果配置多个插件,切记分页最后添加
        return interceptor;
    }

}
